<template>
    <h2>登录</h2>
    <table border="1">
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="state.name">
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password"  v-model="state.pwd">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="登录" @click="login">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { reactive,toRefs } from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter()
const data = reactive({
    state:{
        name:'',
        pwd: ''
    }
})

const {state} = toRefs(data);
const login =()=> {
    axios({
        url:'/api/MemberLogin/Login',
        method:'get',
        params:state.value
    })
    .then(res=>{
        console.log(res);
        if(res.data.data==-1)
        {
            alert('用户名错误！');
            return;
        }
        else if(res.data.data==-2)
        {
            alert('密码错误！');
            return;
        }
        else if(res.data.data!="")
        {
            alert('登录成功！');
            router.push('/ShowMember');
            
        }
        else{
            alert('登录失败！');
            return;
        }

    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>